<template>
	<view>
		<view class="dangan relative">
			<view class="f14 flex-cen" style="color: #FF4800;background-color: #FFDFD2;
			height: 64rpx;">
				请认真填写相关信息
			</view>
			<view class="dangan-yi" v-if="false">
				<view class="dangan-yi-left">
					病例编号：
				</view>
				<view class="dangan-yi-right">
					<input type="text" class=" h100" v-model="form.id">
				</view>
			</view>
			<view class="line"></view>
			<view class="dangan-yi">
				<view class="dangan-yi-left">
					姓名：
				</view>
				<view class="dangan-yi-right">
					<input type="text" class=" h100" v-model="form.xtName">
				</view>
			</view>
			<view class="dangan-yi">
				<view class="dangan-yi-left">
					身份证：
				</view>
				<view class="dangan-yi-right">
					<input type="text" class=" h100" v-model="form.xtIdNumber">
				</view>
			</view>
			<view class="dangan-yi">
				<view class="dangan-yi-left">
					电话：
				</view>
				<view class="dangan-yi-right">
					<input type="number" class=" h100" v-model="form.xtPhone">
				</view>
			</view>
			<view class="line"></view>
			<view class="dangan-er">
				<view class="dangan-yi-left">
					<view class="">
						性别：
					</view>
					<u-radio-group v-model="form.xtGender" iconPlacement="right" @change="groupChange">
						<u-radio v-for="(item, index) in radiolist1" :key="index" :label="item.name" :name="item.type"
							@change="radioChange"></u-radio>
						<!-- <u-radio activeColor="" label="女" :name="'2'"></u-radio> -->
					</u-radio-group>
				</view>
				<view class="dangan-yi-right">
					<view class="">
						年龄：
					</view>
					<input type="number" class=" h100" v-model="form.xtAge">
				</view>
			</view>
			<view class="line"></view>
			<view class="dangan-yi">
				<view class="dangan-yi-left">
					身高：
				</view>
				<view class="dangan-yi-right">
					<input type="number" class=" h100" v-model="form.height">
				</view>
				CM
			</view>
			<view class="dangan-yi">
				<view class="dangan-yi-left">
					体重：
				</view>
				<view class="dangan-yi-right">
					<input type="number" class=" h100" v-model="form.weight">
				</view>
				KG
			</view>
			<view class="dangan-yi">
				<view class="dangan-yi-left">
					关系：
				</view>
				<u-radio-group v-model="form.xtRelationship" iconPlacement="right" @change="groupChange2">
					<u-radio v-for="(item, index) in radiolist2" :key="index" :label="item.name" :name="item.type"
						></u-radio>
				</u-radio-group>
			</view>

			<view class="dangan-san">
				<view class="dangan-san-hd">
					患者病史：
				</view>
				<view class="dangan-san-db">
					<textarea name="text" cols="40" rows="10" v-model="form.medicalHistory"></textarea>
				</view>
			</view>
			<view class="line"></view>
			<view class="dangan-san">
				<view class="dangan-san-hd">
					患者过敏病史:
				</view>
				<view class="dangan-san-db">
					<textarea name="text" cols="40" rows="10" v-model="form.allergicHistory"></textarea>
				</view>
			</view>

			<!--  -->
			<view class="di main ">
				<button class="btn  btn-big" @click="send" hover-class="btn-hor">确认</button>
			</view>
		</view>
	</view>
</template>

<script>
	import {
		telVerification,
		xtIdVerification,
	} from "@/utils/myFun.js";
	export default {
		data() {
			return {
				radiolist1: [{
						name: '男',
						type: '1'
					},
					{
						name: '女',
						type: '2'
					},
				],
				
				radiolist2: [
					{
						name: '父母',
						type: '1'
					},
					{
						name: '兄弟',
						type: '2'
					},
					{
						name: '儿女',
						type: '3'
					},
					{
						name: '其他',
						type: '4'
					}
				],

				form: {
					"xtUserFamily": null,
					"xtName": null,
					"xtIdNumber": null,
					"xtPhone": null,
					"xtGender": "1",
					"xtAge": null,
					"xtRelationship": null,
					"allergicHistory": '',
					"medicalHistory": '',
					'height': null,
					'weight': null
				},
				changeOrAddStatus: false,
				e: null
			};
		},
		methods: {
			radioChange(){
				
			},
			groupChange(e) {
				console.log(e, "e")
				this.form.xtGender = e
			},
			groupChange2(e) {
				console.log(e, "e")
				this.form.xtRelationship = e
			},
			async send() {
				let {
					xtName,
					xtIdNumber,
					xtPhone,
					xtAge,
					height,
					weight,
					xtRelationship,
					medicalHistory,
					allergicHistory
				} = this.form;
				console.log(this.form)
				if (xtName == '' || xtName == undefined || xtName == null) {
					uni.showToast({
						icon: 'none',
						title: "姓名不能为空",
					});
					return;
				}
				
				if (!xtIdVerification(xtIdNumber)) {
					uni.showToast({
						icon: 'none',
						title: '请输入正确的身份证号码'
					})
					return
				}
				if (!telVerification(xtPhone)) {
					uni.showToast({
						icon: 'none',
						title: '请输入正确的11位手机号'
					})
					return
				}
				if (xtAge == '' || xtAge == undefined || xtAge == null) {
					uni.showToast({
						icon: 'none',
						title: "年龄不能为空",
					});
					return
				}
				if (height == '' || height == undefined || height == null) {
					uni.showToast({
						icon: 'none',
						title: "身高不能为空",
					});
					return
				}
				if (weight == '' || weight == undefined || weight == null) {
					uni.showToast({
						icon: 'none',
						title: "体重不能为空",
					});
					return
				}
				console.log(xtRelationship)
				if (xtRelationship == '' || xtRelationship == undefined || xtRelationship == null || xtRelationship ==
					0) {
					uni.showToast({
						icon: 'none',
						title: "请选择关系",
					});
					return
				}
				
				if (this.changeOrAddStatus) {
					await this.$API.familyApi.changeList(this.form)
					uni.showToast({
						title: '修改成功'
					})
					uni.navigateBack()
				} else {
					await this.$API.familyApi.addList(this.form)
					uni.showToast({
						title: '新增成功'
					})
					uni.navigateBack()
				}
			},
		},
		onLoad(options) {
			if (options.data) {
				let data = JSON.parse(options.data)
				this.form = data
				console.log(data, "data");
				this.changeOrAddStatus = true
			} else {
				console.log('options不存在');
				this.changeOrAddStatus = false
			}
		},
		onShow() {},

	}
</script>

<style lang="scss">
	.dangan {
		.dangan-yi {
			padding: 0 40rpx;
			line-height: 100rpx;
			display: flex;
			font-size: 29rpx;
			letter-spacing: 5rpx;

			// justify-content: space-evenly;
			.dangan-yi-left {
				// text-align: center;
				// width: 160rpx;
				padding-right: 30rpx;
			}

			.dangan-yi-right {
				width: 430rpx;
			}
		}

		.dangan-er {
			padding: 0 40rpx;
			line-height: 100rpx;
			// display: flex;
			font-size: 30rpx;
			display: flex;
			letter-spacing: 5rpx;
			box-sizing: border-box;

			.dangan-yi-left {
				width: 50%;
				display: flex;
				// background-color: red;
				align-items: center;

				input {
					width: 230rpx;
				}
			}

			.dangan-yi-right {
				width: 50%;
				display: flex;
				// background-color: red;
				align-items: center;

				input {
					width: 230rpx;
				}
			}
		}

		.dangan-san {
			padding: 20rpx 40rpx;
			font-size: 30rpx;
			letter-spacing: 5rpx;

			.dangan-san-db {
				margin-top: 20rpx;
			}
		}
	}
</style>